﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>普通页面</title>
    <!-- Bootstrap -->
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="/CSS/Base/BaseClass.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none; /*元素不能被选中*/
        }

        .lev1 {
            /*//  margin-left: 10px;*/
        }

        .lev2 {
            padding-left: 40px;
        }

        .list-group .lev2:first-child {
            padding-left: 40px;
            border-top: 1px solid #ddd !important;
        }

        .peples .list-group-item {
            padding-bottom: 5px;
            padding-top: 5px;
        }

        .media-left {
            padding-right: 5px;
        }

        .media-body {
            padding-top: 5px;
        }

        .media-heading {
            margin-top: 8px;
        }

        .list-group-item:hover {
            background-color: #3085DB;
        }


        .isel {
            position: absolute;
            top: 18px;
            right: 10px;
            color: darkgoldenrod;
            font-size: 18px;
        }

        .pCard {
            min-width: 80px;
            text-align: center;
            margin: 8px 3px;
        }

            .pCard:hover .badge {
                visibility: visible;
            }

        .panel-body .badge {
            position: absolute;
            top: -5px;
            right: -6px;
            background-color: red;
            padding-left: 5px;
            padding-right: 5px;
            visibility: collapse;
        }
    </style>
</head>
<body ms-controller="UserSelect">
    <div class="container-fluid" style="margin:10px" id="dvContent">

        <div style="width:200px;position:absolute">
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">组织机构<a href="#" ms-click="SelBMFun('')">（全部人员）</a></div>
                <!-- List group -->
                <ul class="list-group" ms-each-bm="BMLIST">
                    <li class="list-group-item" ms-class="active:bm.DeptCode==selBM.DeptCode" ms-click="SelBMFun(bm)">
                        {{bm.DeptName}}
                    </li>
                    <ui class="list-group" ms-each-item="bm.xsbm">
                        <li class="list-group-item lev2" ms-class="active:item.DeptCode==selBM.DeptCode" ms-click="SelBMFun(item)"> {{item.DeptName}}</li>
                    </ui>
                </ul>
            </div>
        </div>
        <div class="row" style="margin-left:211px; margin-right:0">
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">已选择人员({{SelUsers.size()}})</div>
                <!-- List group -->
                <div class="panel-body " style="padding-top: 0;padding-bottom: 0;min-height:50px;max-height:120px;overflow:auto">
                    <div class="pCard" ms-repeat-seluser="SelUsers">
                        <span class="badge" ms-click="DelSelUser(seluser)">X</span>
                        <div class="pName">{{seluser.UserRealName}}</div>
                    </div>
                </div>
            </div>
            <div class="panel panel-default peples">
                <!-- Default panel contents -->
                <div class="panel-heading">人员列表<span class="text-info">({{QueryUsers.size()}})</span><i class="fa fa-square pull-right isel" ms-if="isSignle=='N'" ms-click="SelUserAll(this)" style="position:inherit"></i></div>
                <!-- List group -->
                <ul class="list-group" style=" max-height:350px;overflow: auto;">
                    <li class="list-group-item" ms-repeat-user="QueryUsers" ms-click="SelUser(user,this)">
                        <div class="media">
                            <div class="media-left">
                                <a href="#">
                                    <img class="media-object" onerror="javascript: this.src = '/images/TX/default.png'" ms-attr-src="'/images/TX/'+user.UserName+'.jpg'" style="width:45px; height:45px">
                                </a>
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading">{{user.UserRealName}}</h5>
                                <i class="fa isel fa-check-square pull-right" ms-if="user.issel"></i>
                            </div>
                        </div>
                    </li>
                    <!--<li class="list-group-item">
                        <div class="media" style="width:200px">
                            <div class="media-left">
                                <a href="#">
                                    <img class="media-object" src="/images/TX/default.png" style="width:45px; height:45px">
                                </a>
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading">张三</h5>
                            </div>
                        </div>
                        <i class="fa fa-check-square pull-right isel" ms-class-fa-square="!user.issel"></i>
                    </li>-->
                </ul>
            </div>
        </div>
    </div>
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/SZHLCommon.js"></script>
    <script>
        var model = avalon.define({
            $id: "UserSelect",
            isSignle: ComFunJS.getQueryString("issignle") ? ComFunJS.getQueryString("issignle") : "N",
            checkval: ComFunJS.getQueryString("checkvalue") ? ComFunJS.getQueryString("checkvalue") : "",
            selBM: {},//已选择部门
            SelBMFun: function (el) {
                if (el) {
                    model.selBM = el;
                } else {
                    model.selBM = {};
                }
                $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERBYCODENEW', { P1: model.selBM.DeptCode }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        resultData.Result.forEach(function (el) {
                            if (ComFunJS.FindItem(model.SelUsers, function (e) {
                     return e.UserName == el.UserName;
                            }).length == 0) {
                                el.issel = false
                            } else {
                                el.issel = true
                            }
                            //el.issel = false;
                        })
                        model.QueryUsers = resultData.Result;
                    }
                })
            },

            SelUser: function (item, dom) {
                if (model.isSignle == "Y") {
                    model.SelUsers.clear();
                    model.QueryUsers.forEach(function (user) {
                        user.issel = false;
                    })

                }
                item.issel = !item.issel;
                if (!item.issel) {
                    ComFunJS.DelItem(model.SelUsers, "UserName", item.UserName)
                } else {
                    if (ComFunJS.FindItem(model.SelUsers, function (e) {
                      return e.UserName == item.UserName;
                    }).length == 0) {
                        model.SelUsers.push(item)
                    }
                }
            },
            SelUserAll: function (dom) {
                if ($(dom).hasClass("fa-square")) {
                    model.QueryUsers.forEach(function (item) {
                        item.issel = true;
                        if (ComFunJS.FindItem(model.SelUsers, function (e) {
                   return e.UserName == item.UserName;
                        }).length == 0) {
                            model.SelUsers.push(item)
                        }
                    })
                    $(dom).removeClass("fa-square").addClass("fa-check-square")
                } else {
                    model.QueryUsers.forEach(function (item) {
                        item.issel = false;
                        ComFunJS.DelItem(model.SelUsers, "UserName", item.UserName)

                    })
                    $(dom).removeClass("fa-check-square").addClass("fa-square")
                }

            },
            SelUsers: [],//已选择用户
            DelSelUser: function (item) {
                ComFunJS.DelItem(model.SelUsers, "UserName", item.UserName);
                model.QueryUsers.forEach(function (el) {
                    if (el.UserName == item.UserName) {
                        el.issel = false;
                    }
                })
            },
            BMLIST: [],//部门列表
            QueryUsers: [],//查询用户结果
            render: function () {

            }
        })
        avalon.ready(function () {
            ComFunJS.initsetajax();
            $.getJSON('/API/SZHLAPI.ashx?Action=GETAllBMLIST', { P1: "1" }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.BMLIST = resultData.Result;
                    avalon.scan()
                }
            })
            $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERBYCODENEW', { P1: model.selBM.DeptCode }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    resultData.Result.forEach(function (el) {
                        el.issel = false;
                        $.each(model.checkval.split(','), function (i, n) {
                            if (n == el.UserName) {
                                el.issel = true;
                                model.SelUsers.push(el)

                            }

                        });

                    })
                    model.QueryUsers = resultData.Result;

                    avalon.scan()
                }
            })
        })
        function getqiandaopeople() {
            var userid = "";
            var username = "";

            model.SelUsers.forEach(function (item) {
                userid = userid + item.UserName + ",";
                username = username + item.UserRealName + ",";

            })
            userid = userid.substr(0, userid.length - 1);
            username = username.substr(0, username.length - 1);
            var people = { 'userid': userid, 'username': username };
            return people;

        }
    </script>
</body>
</html>